
// let buffer = new Buffer('sssss','utf8');

// console.log(buffer.toString('utf8',0,3));


//https://www.npmjs.com/package/iconv-lite
// npm install iconv-lite
//iconv模块可以实现  data的Buffer 数据编码转换
const fs = require('fs');
const path = require('path');
const iconv = require('iconv-lite');

fs.readFile(path.join(__dirname,'test333'),(error,data)=>{
    if(error) throw error;
    // console.log(iconv.decode(data,'gbk'));

    var lines =iconv.decode(data,'utf8').split('\n');
    //console.log(lines);


    // lines.forEach(line => {
    //     //[00:32.67] 也许我告别 将不在回来
    //     var regex = /\[\d{2}\:\d{2}\.\d{2}\]\s.+/;
    //     let v = regex.test(line);
    //     console.log(v);
    // });

    var regex = /\[(\d{2})\:(\d{2})\.(\d{2})\]\s(.+)/;
    lines.forEach(line => {
        var matches = regex.exec(line);
        if(matches){
            var m = parseInt(matches[1]);
            var s = parseInt(matches[2]);
            var f = parseInt(matches[3]);
            var lyric = matches[4];
            console.log(m);
            console.log(s);
            console.log(f);
            console.log(lyric);
        }else{
           console.log(line); 
        }
    });

})
